﻿package com.cilico.single.utils;


import android.app.Activity;

/**
 * 
 * @author lv.xiangan
 *
 */
public class InputDB extends RmsDatabase {
	private final String CHANNEL_ID = "CHANNEL_ID";
	private String prefix_;

	public InputDB(Activity app_, String dbname) throws Exception {
		super(app_, dbname);
	}

	public String getRecord(String channelID) {
		String record = null;
		try {
			prefix_ = CHANNEL_ID + channelID;
			String s = this.get(prefix_);
			if ((null == s) || (s.equalsIgnoreCase("")))
				return null;
			record = s.substring(prefix_.length()).trim();
			if (record.equals(""))
				record = null;
		} catch (Exception ex) {
			Utils.printException(ex);
		} finally {

		}
		return record;
	}

	public void restoreRecord(String channelID, String record) {
		try {
			if (record == null || record.equals(""))
				return;
			String newrecord = CHANNEL_ID + channelID + record;
			prefix_ = CHANNEL_ID + channelID;
			byte[] byt = newrecord.getBytes("UTF-8");
			this.save(prefix_, new String(byt));
		} catch (Exception ex) {

			Utils.printException(ex);
		} finally {

		}
	}

	@SuppressWarnings("unused")
	public boolean matches(byte[] b) {
		if (b == null || b.length < 1)
			return false;
		String s;
		try {
			s = new String(b, "UTF-8");
			if (s == null)
				throw new NullPointerException();
		} catch (Exception ex) {

			Utils.printException(ex);
			return false;
		}
		if (s.startsWith(prefix_)) {
			return true;
		} else {
			return false;
		}
	}

}
